//
//  MainTabBarController.swift
//  DigitalMuseum
//
//  Created by HzS on 2024/2/21.
//

import UIKit

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        // 添加所有的vc
        addChildren()
        // 配置tabBar
        configTabBar()
    }
    
    // MARK: - Helper
    
    private func configTabBar() {
        // 未选中颜色
        tabBar.unselectedItemTintColor = UIColor(hexString: "#AAAEB8")
        // 选中颜色
//        tabBar.tintColor = .schemeColor
        // 背景颜色
        tabBar.barTintColor = UIColor(hexString: "#F2F3F4")
        tabBar.backgroundColor = UIColor(hexString: "#F2F3F4")
        // 不透明
        tabBar.isTranslucent = false
        if #available(iOS 13, *) {
            let appearance = UITabBarAppearance()
            appearance.configureWithOpaqueBackground() // 不透明
            appearance.backgroundColor = UIColor(hexString: "#F2F3F4") // 背景颜色
            tabBar.standardAppearance = appearance
            if #available(iOS 15, *) {
                tabBar.scrollEdgeAppearance = appearance
            }
        }
    }
    
    private func addChildren() {
        addChildController(HomeViewController(), title: "首页", imageName: "", selectedImageName: "")
        addChildController(NFTViewController(), title: "数字藏品", imageName: "", selectedImageName: "")
        addChildController(CommunityViewController(), title: "社区", imageName: "", selectedImageName: "")
        addChildController(UserCenterViewController(), title: "我的", imageName: "", selectedImageName: "")
    }
    
    private func addChildController(_ vc: UIViewController, title: String, imageName: String, selectedImageName: String) {
        vc.title = title
        vc.tabBarItem = UITabBarItem(title: title, image: UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage(named: selectedImageName)?.withRenderingMode(.alwaysTemplate))
        let nav = DMNavigationController(rootViewController: vc)
        addChild(nav)
    }

}
